package com.heima.behavior.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.behavior.dto.LikeDto;
import com.heima.behavior.dto.LikesBehaviorDto;
import com.heima.behavior.entity.ApLikesBehavior;
import com.heima.behavior.service.IApLikesBehaviorService;
import com.heima.common.dto.ResponseResult;
import io.swagger.annotations.Api;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * APP点赞行为表 前端控制器
 * </p>
 *
 * @author mcm
 * @since 2022-01-18
 */
@RestController
@RequestMapping("/api/v1/likes_behavior")
@Api(tags = "APP点赞行为表接口")
public class ApLikesBehaviorController{

    @Autowired
    private IApLikesBehaviorService apLikesBehaviorService;

    /**
     * 点赞或取消点赞
     * @param dto
     * @return
     */
    @PostMapping
    public ResponseResult<ApLikesBehavior> saveLike(@RequestBody LikesBehaviorDto dto){
        return apLikesBehaviorService.saveLike(dto);
    }



    @PostMapping("/getLike")
    public ApLikesBehavior getLike(@RequestBody LikeDto dto){
        LambdaQueryWrapper<ApLikesBehavior> wrapper = new LambdaQueryWrapper<>();

        wrapper.eq(ApLikesBehavior::getArticleId,dto.getArticleId());

        return apLikesBehaviorService.getOne(wrapper);
    }


}
